﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using RoadTeam.Model;
using RoadTeam.Enums;
using RoadTeam.SysInterface;


namespace RoadTeam.BLL
{
    public class CsValidateRoomPicBll
    {
        private static object o = new object();

        public bool Insert(String BusninessIdentifier, String FilePath, String RtFilePath, String FileName)
        {
            CsValidateRoomPic pic = new CsValidateRoomPic();
            DataTable dt = FactoryClass.CreateCsValidateRoomPic().GetEmptyTable();
            DataRow dr = dt.NewRow();

            lock (o)
            {
                String PicIdentifier = Pub.CreateIdentifier.GetIdentifier();
                dr[0] = FactoryClass.CreateCsValidateRoom().GetValidateRoomID(BusninessIdentifier);
                dr[1] = FilePath+"/";
                dr[2] = FileName;
                dr[3] = PicIdentifier;
                dt.Rows.Add(dr);

                pic.BusninessIdentifier = BusninessIdentifier;
                pic.ImageName = FileName;
                pic.ImagePath = RtFilePath;
                pic.RoomPicIdentifier = PicIdentifier;
            }
            bool flag = false;
            flag = FactoryClass.CreateCsValidateRoomPic().Insert(dt);
            flag = CsValidateRoomPic.InserObjedct(pic, new List<string>(), GlobalConfig.ConnectionString);
            return flag;
        }

        public DataTable GetEmptyTable()
        {
            SqlWhere where = new SqlWhere();
            where.Info = new CsValidateRoomPic() { RoomPicIdentifier = @"-1" };
            return CsValidateRoomPic.Select(where, GlobalConfig.RtConnectionString);
        }
    }
}
